package com.dunshan.dunshanfile.controller;

import org.springframework.stereotype.Controller;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Random;

/**
 * @author
 * @program: dunshan-pef
 * @description:
 * @date 2022-01-23 09:47:19
 */
@Controller
@RestController
public class PassController {

    @GetMapping("/md5")
    public Object md5BCryptPasswordEncoder() {
        HashMap<String, Object> map = new HashMap<>();
        Random random = new Random();
        int salt = random.nextInt(100);
        String user = "werwrw" + salt;
        String md5Password = DigestUtils.md5DigestAsHex(user.getBytes());
        map.put("md5", md5Password);
        return map;
    }

//    @GetMapping("/bCrypt")
//    public Object bCryptPasswordEncoder() {
//        Random random = new Random();
//        int i = random.nextInt(100);
//        String password = "werwrw" + i;
//        HashMap<String, Object> map = new HashMap<>();
//        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
//        String newPassword = passwordEncoder.encode(password);
//        map.put("bCrypt", newPassword);
//        return map;
//    }
}
